﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kivensoft.Helper;
using System.IO;

namespace XlsxLibTest {
	class Program {
		static void Main(string[] args) {
			var headers = new string[] { "姓名", "年龄", "电话", "家庭住址", "余额" };
			var widths = new float[] {14f, 12f, 20f, 22f, 10f};

			var xls = new XlsxExport("工作表33");
			xls.SetTitle("大标题", new string[] {"查询日期", "打印日期"},
				new int[] {3, 2}, headers, widths);
			
			xls.GoToNextRow();
			xls.AddNextCell("Kiven", true);
			xls.AddNextCell(42);
			xls.AddNextCellDateTime(DateTime.Now);
			xls.AddNextCellDate(DateTime.Today);
			xls.AddNextCellMoney(3459.8);

			xls.GoToNextRow();
			xls.AddNextCell("Kiven2", true);
			xls.AddNextCell(76);
			xls.AddNextCellDateTime(DateTime.Now);
			xls.AddNextCellDate(DateTime.Today);
			xls.AddNextCellMoney(4421);

			xls.SetFooter("合计", 3, new bool[] {false, true});
			
			var f = File.Open(@"z:\测试.xlsx", FileMode.Create);
			xls.Write(f);
			f.Close();

			f = File.Open(@"z:\测试.xlsx", FileMode.Open, FileAccess.Read);
			var reader = new XlsxImport(f, headers);
			while (reader.NextRow()) {
				Console.WriteLine("{0}, {1}, {2}, {3}, {4}\n", 
					reader.CellAsString(0),
					reader.CellAsInt(1),
					reader.CellAsDateTime(2),
					reader.CellAsDate(3),
					reader.CellAsDecimal(4));
			}
			f.Close();
		}
	}
}
